*November 16, 2025
**Wilk, Deza, Hodge, Danagoulian (2025) Couch-Locked with the Munchies: Effects of Recreational Marijuana Laws on Exercise and Nutrition
**This code creates the following: 
*From main paper: Tables 6 and Figures 2 
*From Online Appendix: Table A1-A4-A7-A13

***************************************************
*These tables and figures can be used after downloading the following
*BRFSS: LLCP2011.XPT-LLCP2017.XPT
*"~/Dropbox/Medical_Marijuana_Laws/Data/controls_cdcdatawonder.dta"
**************************************************

***************************************************
**BRFSS: KEEP RELEVANT VARIABLES AND APPEND 2011-2021
***************************************************
	**Datasets to import and export
		forvalues y=2011/2021 {
			local data`y' "~/Dropbox/Monica/mar_munchies/brfss/LLCP`y'.XPT"
			local dataout`y' "~/Dropbox/Monica/mar_munchies/brfss/brfss`y'.XPT"
		}
	**List for variables we will keep for every wave
		local vars2011="_state iyear imonth age sex  exerany2  _llcpwt  exract01 exract02 exeroft1 exeroft2"
		local vars2012 "_state iyear imonth age sex  exerany2 _llcpwt  "
		local vars2013 "_state iyear imonth _age80 sex  exerany2  _llcpwt   exract11 exract21 exeroft1 exeroft2"
		local vars2014 "_state iyear imonth _age80 sex  exerany2  _llcpwt"
		local vars2015 "_state iyear imonth _age80 sex exerany2  _llcpwt  exract11 exract21 exeroft1 exeroft2"
		local vars2016 "_state iyear imonth _age80 sex exerany2 _llcpwt"
		local vars2017 "_state iyear imonth _age80 sex  exerany2  _llcpwt exract11 exract21 exeroft1 exeroft2"
		local vars2018 "_state iyear imonth _age80 sex1  exerany2 _llcpwt "
		local vars2019 "_state iyear imonth _age80 sex  exerany2 _llcpwt  exract11 exract21 exeroft1 exeroft2"
		local vars2020 "_state iyear imonth _age80 sexvar  exerany2 _llcpwt "
		local vars2021="_state iyear imonth _age80 sexvar exerany2 _llcpwt "
	
	**Append 2011-2021 raw BRFSS with relevant variables 
		*2011
			clear
			import sasxport5 `data2011', clear
			keep `vars2011'
			rename exract01 exract11
			rename exract02 exract21
			tempfile rawdata2011
			save `rawdata2011'
		*2012
			clear
			import sasxport5 `data2012', clear
			keep `vars2012'
			tempfile rawdata2012
			save `rawdata2012'  
		**2013-2014-2015-2016-2017-2019
			foreach y in 2013 2014 2015 2016 2017  2019  {
				clear
				import sasxport5 `data`y'', clear
				keep `vars`y''
				rename _age80 age 
				replace sex=. if (sex==7|sex==9)
				tempfile rawdata`y'
				save `rawdata`y''
			}  
		**2020-2021
			foreach y in 2020 2021 {
				clear
				import sasxport5 `data`y'', clear
				keep `vars`y''
				rename _age80 age 
				rename sexvar sex 
				tempfile rawdata`y'
				save `rawdata`y''
			}  
		**2018
			foreach y in 2018 {
				clear
				import sasxport5 `data`y'', clear
				keep `vars`y''
				rename _age80 age 
				rename sex1 sex
				replace sex=. if (sex==7|sex==9)
				tempfile rawdata`y'
				save `rawdata`y''
			}  
		**Append data
			clear
			use `rawdata2011'
			forvalues y=2012/2021 {
				append using `rawdata`y'', force
		}
***************************************************
**BRFSS: CLEAN RELEVANT VARIABLES FOR 2011-2021
***************************************************
	**(1)State fips
		ren _state fips
		keep if inrange(fips,1,56)
		
	**(2)Month and year of interview
		destring iyear, g(year)
		drop iyear
		
	**(3)destring imonth, g(month)
		destring imonth, replace
		assert imonth>=1 & imonth<=12
		recode imonth (1/3=1) (4/6=2) (7/9=3) (10/12=4), g(quarter)
		rename imonth month
		
	*(4)Age 
		keep if inrange(age,18,99)
		
	**(5)sex (sex1 in 2018 but same codes)
	*1=male 
	*2=females
	*7=dont know, not sure 
		assert (sex==1|sex==2|sex==.)
		gen male=(sex==1) if (sex==1|sex==2)
		drop sex

	**(6)Exerany2: (During the past month, other than your regular job, did you participate in any physical activities or exercises such as running, calisthetics, golf, gardedning or walking for distance?
	*1=yes
	*2=no
	*7=dont know , not sure
	*9=refused 
	*blank 
		gen exercise_lm=(exerany2==1) if (exerany2==1|exerany2==2)
		replace exerany2=. if (exerany2==7|exerany2==9|exerany2==.)

	**(7) At least once a week walking/running/jogging/swimming in the past month 
		gen cardioweek_lm=0
		replace cardioweek_lm=1 if ((exeroft1>=101 & exeroft2<200)|(exeroft2>=101 & exeroft2<200))
		replace cardioweek_lm=. if ((exeroft1==777|exeroft1==999) & (exeroft2==777|exeroft2==999))
		replace cardioweek_lm=0 if exercise_lm==0	
		replace cardioweek_lm=. if (year==2012|year==2014|year==2016|year==2018|year==2020|year==2021|year==2022)
		
	**Keep relevant variables 
	keep fips year month age male exercise_lm  _llcpwt cardioweek_lm 

****************************************
**Create RML and MML dates (when sames start)
*******************************
	gen mml_start=.
	gen rml_start=.
	gen month_mml_start=. 
	gen month_rml_start=. 

	*Alabama, MML effective 05/17/2021, start NA				
	*Alaska, MML sales start: N/A, RML sales start 10/29/2016
		replace rml_start=2016 if fips==2	
		replace month_rml_start=10 if fips==2		
	*Arizona, MML sales start 12/06/2012, RML sales start 1/22/2021
		replace mml_start=2012 if fips==4
		replace rml_start=2021 if fips==4	
		replace month_mml_start=12 if fips==4
		replace month_rml_start=1 if fips==4	
	*Arkansas, MML sales start 05/11/2019, RML sales start (-)
		replace mml_start=2019 if fips==5
		replace month_mml_start=5 if fips==5	
	*California, MML sales start: 01/01/2018, RML sales start: 1/1/2018
		replace mml_start=2018 if fips==6
		replace rml_start=2018 if fips==6
		replace month_mml_start=1 if fips==6
		replace month_rml_start=1 if fips==6
	**Colorado, MML sales start: 10/26/2011, RML sales start: 1/1/2014
		replace mml_start=2011 if fips==8
		replace rml_start=2014 if fips==8
		replace month_mml_start=10 if fips==8
		replace month_rml_start=1 if fips==8
	*Connecticut, MML sales start: 08/20/2014, RML sales start: 1/10/2023
		replace mml_start=2014 if fips==9
		replace rml_start=2023 if fips==9
		replace month_mml_start=8 if fips==9
		replace month_rml_start=1 if fips==9
	*Delaware, MML sales start: 06/26/2015, RML sales start: 2024
		replace mml_start=2015 if fips==10
		replace month_mml_start=6 if fips==10		
	*DC, MML sales start: 07/30/2013, RML sales start: 2/26/2015
		replace mml_start=2013 if fips==11
		replace rml_start=2015 if fips==11
		replace month_mml_start=7 if fips==11
		replace month_rml_start=2 if fips==11
	*Florida, MML sales start: 07/26/2016, RML sales start:(-)
		replace mml_start=2016 if fips==12
		replace month_mml_start=7 if fips==12
	*Georgia (n/a)
	**Hawaii, MML sales start: 08/08/2017, RML sales start: (-)
		replace mml_start=2017 if fips==15
		replace month_mml_start=8 if fips==15
	**Idaho (N/A)
	**Illinois, MML sales start:11/09/2015, RML sales start: 1/1/2020
		replace mml_start=2015 if fips==17
		replace rml_start=2020 if fips==17
		replace month_mml_start=11 if fips==17
		replace month_rml_start=1 if fips==17
	*Indiana (N/A)
	*Iowa (N/A)
	*Kansas (N/A)
	*Kentucky (n/a until 2025)
	*Louisiana, MML sales start:08/06/2019, RML effective :(-)
		replace mml_start=2019 if fips==22
		replace month_mml_start=8 if fips==22
	*Maine, MML sales start: 03/2011, RML sales start: 10/9/2020
		replace mml_start=2011 if fips==23
		replace rml_start=2020 if fips==23
		replace month_mml_start=3 if fips==23
		replace month_rml_start=10 if fips==23
	*Maryland, MML sales start: 12/01/2017, RML sales start: 7/1/2023
		replace mml_start=2017 if fips==24
		replace rml_start=2023 if fips==24
		replace month_mml_start=12 if fips==24
		replace month_rml_start=7 if fips==24
	*Massachusetts, MML sales start: 06/24/2015, RML sales start: 11/20/2018
		replace mml_start=2015 if fips==25
		replace rml_start=2018 if fips==25
		replace month_mml_start=6 if fips==25
		replace month_rml_start=11 if fips==25	
	*Michigan, MML sales start: 08/2018, RML sales start: 12/1/2019
		replace mml_start=2018 if fips==26
		replace rml_start=2019 if fips==26
		replace month_mml_start=8 if fips==26
		replace month_rml_start=12 if fips==26
	*Minnesota, MML sales start: 7/1/2015, RML sales start: (-)
		replace mml_start=2015 if fips==27
		replace month_mml_start=7 if fips==27	
	**Mississippi, MML sales start: 1/25/23, RML sales start: (-)
		replace mml_start=2023 if fips==28
		replace month_mml_start=1 if fips==28
	*Missouri, MML sales start: 10/17/20, RML sales start: 2/3/23
		replace mml_start=2020 if fips==29
		replace rml_start=2023 if fips==29
		replace month_mml_start=10 if fips==29
		replace month_rml_start=2 if fips==29
	*Montana, MML sales start: 4/1/2018, RML sales start: 1/1/2022
		replace mml_start=2018 if fips==30
		replace rml_start=2022 if fips==30
		replace month_mml_start=4 if fips==30
		replace month_rml_start=1 if fips==30
	*Nebraska (N/a)
	*Nevada, MML sales start: 7/31/2015, RML sales start: 7/1/2017
		replace mml_start=2015 if fips==32
		replace rml_start=2017 if fips==32	
		replace month_mml_start=7 if fips==32
		replace month_rml_start=1 if fips==32
	*New Hampshire, MML sales start: 5/1/2016, RML sales start:(-)
		replace mml_start=2016 if fips==33
		replace month_mml_start=5 if fips==33
	*New Jersey, MML sales start: 12/6/2012, RML sales start: 4/20/2022
		replace mml_start=2012 if fips==34
		replace rml_start=2022 if fips==34
		replace month_mml_start=12 if fips==34
		replace month_rml_start=4 if fips==34
	*New MExico, MML sales start: 1/1/2010, RML sales start: 4/1/2022
		replace mml_start=2010 if fips==35
		replace rml_start=2022 if fips==35
		replace month_mml_start=1 if fips==35
		replace month_rml_start=4 if fips==35
	*New York, MML sales start: 1/7/2016, RML sales start: 12/29/22
		replace mml_start=2016 if fips==36
		replace rml_start=2022 if fips==36	
		replace month_mml_start=1 if fips==36
		replace month_rml_start=12 if fips==36
	*North Carolina (N/a)
	*North Dakota, MML sales start: 3/1/2019, RML sales start:(-)
		replace mml_start=2019 if fips==38
		replace month_mml_start=3 if fips==38
	*Ohio, MML sales start: 1/16/2019, RML sales start: (-)
		replace mml_start=2019 if fips==39
		replace month_mml_start=1 if fips==39
	*Oklahoma, MML sales start: 10/26//2018, RML sales start: (-)
		replace mml_start=2018 if fips==40
		replace month_mml_start=10 if fips==40
	*Oregon, MML sales start: 3/21/2014, RML sales start: 10/1/15
		replace mml_start=2014 if fips==41
		replace rml_start=2015 if fips==41
		replace month_mml_start=3 if fips==41
		replace month_rml_start=10 if fips==41
	*Pennsylvania, MML sales start: 2/15/2018, RML sales start: (-)
		replace mml_start=2018 if fips==42
		replace month_mml_start=2 if fips==42
	*Rhode Island 
	*(B)MML sales start: 4/19/2013
	*(D)RML sales start: 12/1/2022
		replace mml_start=2013 if fips==44
		replace rml_start=2022 if fips==44
		replace month_mml_start=4 if fips==44
		replace month_rml_start=12 if fips==44
	*South Carolina : n/a	
	**South Dakota, MML sales start: 7/27/2022, RML sales start :(-)
		replace mml_start=2022 if fips==46
		replace month_mml_start=7 if fips==46
	*Tennessee (n/a)
	*Texas (n/a)	
	*Utah, MML sales start: 3/2/20, RML sales start: (-)
		replace mml_start=2020 if fips==49
		replace month_mml_start=3 if fips==49
	*Vermont, MML sales start: 6/25/2013, RML sales start: 10/1/2022
		replace mml_start=2013 if fips==50
		replace rml_start=2022 if fips==50
		replace month_mml_start=6 if fips==50
			replace month_rml_start=10 if fips==50
	*Virginia, MML sales start: 10/17/2020, RML sales start: (-)
		replace mml_start=2020 if fips==51
		replace month_mml_start=10 if fips==51		
	*Washington, MML sales start: 7/8/2014, RML sales start: 7/8/14
		replace mml_start=2014 if fips==53
		replace rml_start=2014 if fips==53
		replace month_mml_start=7 if fips==53
		replace month_rml_start=7 if fips==53
	*West Virginia, MML sales start: 11/12/2021, RML sales start (-)
		replace mml_start=2021 if fips==54
		replace month_mml_start=11 if fips==54
	*Wisconsin : N/A
	*Wyoming : N/A/ 

*******************************
*Period 1 and Period 2
**Period 1: Post MML, Pre RML
**Period 2: Post RML
*******************************	
**Using years before and after implementation 
	**(a) If there is valid MML and valid RML date
		gen period1_start=(year>mml_start & year<rml_start) if mml_start!=. & rml_start!=.
		gen period2_start=(year>rml_start) if mml_start!=. & rml_start!=.
	
	*(b) If MML is valid, but RML is missing
		replace period1_start=(year>mml_start) if mml_start!=. & rml_start==.
		replace period2_start=0 if mml_start!=. & rml_start==.
	
	*(c)If MML is missing , but RML is valid 
		replace period1_start=0 if mml_start==. & rml_start!=.
		replace period2_start=(year>rml_start) if mml_start==. & rml_start!=.
	
	*(d)If both mml and rml are missing 
		replace period1_start=0 if mml_start==. & rml_start==.
		replace period2_start=0 if mml_start==. & rml_start==.
	
**In the Year of passage, we can use month of implementation (only matters when mml_eff!=. or rml_eff!=.)
*When both dates are valid: mml_eff!=. & rml_eff!=.		
	replace period1_start=1 if month>=month_mml_start & year==mml_start & mml_start!=. & month_mml_start!=.
	replace period1_start=0 if month<month_mml_start & year==mml_start & mml_start!=. & month_mml_start!=.
	
	replace period2_start=1 if month>=month_rml_start & year==rml_start & rml_start!=. & month_rml_start!=.
	replace period2_start=0 if month<month_rml_start & year==rml_start & rml_start!=. & month_rml_start!=.
	
**************************************
**Covid dummies for controlling for stay at home orders
***************************************
*Month is marked as covid month if at least 7 days of the month
	gen covid=0
	replace covid=1 if month==4 & year==2020 & fips==1
	replace covid=1 if (month==4) & year==2020 & fips==2
	replace covid=1 if (month==4|month==5) & year==2020 & fips==4
	replace covid=1 if ((month>=4 & year>=2020)|(month==1 & year==2021)) & fips==6
	replace covid=1 if (month==4) & year==2020 & fips==8
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==9
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==10
	replace covid=1 if (month==4|month==5) & year==2020 & fips==11
	replace covid=1 if (month==4|month==5) & year==2020 & fips==12
	replace covid=1 if (month==4) & year==2020 & fips==13
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==15
	replace covid=1 if (month==3|month==4) & year==2020 & fips==16
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==17
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==18
	replace covid=1 if (month==4) & year==2020 & fips==20
	replace covid=1 if (month==4|month==5|month==6) & year==2020 & fips==21
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==22
	replace covid=1 if (month==4|month==5) & year==2020 & fips==23
	replace covid=1 if (month==4|month==5) & year==2020 & fips==24
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==25
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==26
	replace covid=1 if (month==4|month==5) & year==2020 & fips==27
	replace covid=1 if (month==4) & year==2020 & fips==28 
	replace covid=1 if (month==4) & year==2020 & fips==29
	replace covid=1 if (month==4) & year==2020 & fips==30
	replace covid=1 if (month==4) & year==2020 & fips==32
	replace covid=1 if (month==4|month==5|month==6) & year==2020 & fips==33
	replace covid=1 if (month==3|month==4|month==5|month==6) & year==2020 & fips==34
	replace covid=1 if (month>=3 & month<=11) & year==2020 & fips==35
	replace covid=1 if (month>=3 & month<=6) & year==2020 & fips==36
	replace covid=1 if (month==4|month==5) & year==2020 & fips==37
	replace covid=1 if (month==3|month==4|month==5) & year==2020 & fips==39
	replace covid=1 if (month==4|month==5) & year==2020 & fips==40
	replace covid=1 if (month>=3 & month<=6) & year==2020 & fips==41
	replace covid=1 if (month==4|month==5) & year==2020 & fips==42
	replace covid=1 if (month==4|month==5) & year==2020 & fips==44
	replace covid=1 if (month==4) & year==2020 & fips==45
	replace covid=1 if month==4 & year==2020 & fips==47 
	replace covid=1 if month==4 & year==2020 & fips==48
	replace covid=1 if (month>=3 & month<=5) & year==2020 & fips==50
	replace covid=1 if (month>=4 & month<=5) & year==2020 & fips==51
	replace covid=1 if (month>=3 & month<=5) & year==2020 & fips==53
	replace covid=1 if (month==3|month==4) & year==2020 & fips==54
	replace covid=1 if (month>=3 & month<=5) & year==2020 & fips==55
****************************************
**BJS timing 
****************************************
		sort year month
		egen yearmonth=group(year month)
	**Ei for FOR DID_INFERENCE 
		sort year month 
		*GVAR
		gen groupvar=0	
		*fips=2 (october 2016)
		replace groupvar=70 if fips==2 
		**fips 4 all 2021+			
		replace groupvar=124 if fips==4 
		**fips 5 all 2018+	
		replace groupvar=85 if fips==6 
		**fips 8 all 2014+
		replace groupvar=37 if fips==8 
		**fips 9 all 2023+
		**fips 10 all 2024+
		**fips 11 feb 2015
		replace groupvar=50 if fips==11 
		**fips 17 2020plus
		replace groupvar=109 if fips==17 
		*fips 23 oct 2020
		replace groupvar=118 if fips==23 
		*fips 24 july 2023
		*fips 25 november 2018
		replace groupvar=95 if fips==25 
		*fips 26 dec 2019
		replace groupvar=108 if fips==26 
		*fips 29 , 2023+
		*fips 30, 2022+
		*fips 32, july 2017
		replace groupvar=79 if fips==32 
		*fips 34, 2022
		*fips 36, 2022
		*fips 41, oct 2015
		replace groupvar=58 if fips==41 
		*fips 44, 2022+
		*fips 50, 2022+
		*fips 53, july 2014
		replace groupvar=43 if fips==53 

***********************************************
*** Merge state level characteristics ***
***********************************************
	sum year
	rename fips statefips
	merge m:1 year statefips using "~/Dropbox/Medical_Marijuana_Laws/Data/controls_cdcdatawonder.dta"
	**2011-2021 (once we merge, we have all years)
	keep if _merge == 3
	drop _merge	

*******************************************
**Universe 
****************************************
	keep if year>=2011 & year<=2021
	keep if age>=21 & age!=.	
	tempfile brfss_data 
	save "`brfss_data'"

*******************************************
**Table 6: BJS with different FE and controls 
*****************************************
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
	**DID_INFERENCE 
		rename groupvar Ei
		replace Ei=. if Ei==0
	**BJS FE 
		local bjs_controls0="period1_start statefips year"
		local bjs_controls1="month age covid  male period1_start statefips year"
	*******************************
	**BORUSYAK FOR OUTCOMES THAT APPEAR EVERY YEAR 
	*controls(blackshare maleshare age1825share)
	*************************************
	foreach y in "exercise_lm"  "cardioweek_lm" {	 	
		**All: Basic FE
		eststo clear
		di "outcome `y', sample=All, FE0"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt], fe(`bjs_controls0')  cluster(statefips)	
		sum `y' if e(sample)==1
					 
		**All, Full FE 
		eststo clear
		di "outcome `y', sample=All, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt], fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1
		
		**Male: Basic FE
		eststo clear
		di "outcome `y', sample=Male, FE0"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==1, fe(`bjs_controls0')  cluster(statefips)	
		sum `y' if e(sample)==1
					 
		**Male , Full FE 
		eststo clear
		di "outcome `y', sample=Male, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==1, fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1
		
		**Female: Basic FE
		eststo clear
		di "outcome `y', sample=Female, FE0"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==0, fe(`bjs_controls0')  cluster(statefips)	
		sum `y' if e(sample)==1
					 
		**Female , Full FE 
		eststo clear
		di "outcome `y', sample=Female, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==0, fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1
		}

*******************************************
**Table A1: BJS by age group
*****************************************
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
	**DID_INFERENCE 
		rename groupvar Ei
		replace Ei=. if Ei==0
	**BJS FE 
		local bjs_controls1="month age covid  male period1_start statefips year"
	*******************************
	**BORUSYAK FOR OUTCOMES THAT APPEAR EVERY YEAR 
	*controls(blackshare maleshare age1825share)
	*************************************
	foreach y in "exercise_lm"  "cardioweek_lm" {	 						 
		**Age 21-24, Full FE 
		eststo clear
		di "outcome `y', sample=age 21-24, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age<=24, fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1

		**Age 25-39 , Full FE 
		eststo clear
		di "outcome `y', sample=age 25-39, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if age>=25 & age<=39, fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1
							 
		**Age 40+ , Full FE 
		eststo clear
		di "outcome `y', sample=age 40+, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if age>=40 & age!=., fe(`bjs_controls1') cluster(statefips) 
		sum `y' if e(sample)==1
		}
		
*********************************************
**Table A4: TWFE and Gardner 
*********************************************
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
	**Controls
	local controls1="i.month i.age i.covid  i.male i.period1_start i.statefips i.year"
	local cont_controls="blackshare maleshare age1825share"

	foreach y in "exercise_lm"   "cardioweek_lm"  {	
		*All, TWFFE		
			eststo clear 
			di "outcome `y', sample=All, TWFE"
			qui eststo :reg `y' period2_start `controls1' `cont_controls' [aw=_llcpwt], cluster(statefips)
			display _b[period2_start]
			display _se[period2_start]
			sum `y' if e(sample)==1	
		*All, Gardner		
			eststo clear 
			di "outcome `y', sample=All, Gardner"
			eststo :did2s `y'  [aw=_llcpwt], first_stage(`controls1') second_stage(period2_start) treatment(period2_start) cluster(statefips)
			sum `y' if e(sample)==1		
		*Male, TWFFE		
			eststo clear 
			di "outcome `y', sample=Male, TWFE"
			qui eststo :reg `y' period2_start `controls1' `cont_controls' [aw=_llcpwt] if male==1, cluster(statefips)
			display _b[period2_start]
			display _se[period2_start]
			sum `y' if e(sample)==1	
		*Male, Gardner		
			eststo clear 
			di "outcome `y', sample=Male, Gardner FE1"
			eststo :did2s `y'  [aw=_llcpwt] if male==1, first_stage(`controls1') second_stage(period2_start) treatment(period2_start) cluster(statefips)
			sum `y' if e(sample)==1		
		*Female, TWFFE		
			eststo clear 
			di "outcome `y', sample=Female, TWFE FE1"
			qui eststo :reg `y' period2_start `controls1' `cont_controls' [aw=_llcpwt] if male==0, cluster(statefips)
			display _b[period2_start]
			display _se[period2_start]
			sum `y' if e(sample)==1	
		*Female, Gardner		
			eststo clear 
			di "outcome `y', sample=Female, Gardner FE1"
			eststo :did2s `y'  [aw=_llcpwt] if male==0, first_stage(`controls1') second_stage(period2_start) treatment(period2_start) cluster(statefips)
			sum `y' if e(sample)==1		
	}
	
********************************************************
**Table A7: Include state by month FE 
********************************************************	
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
	**DID_INFERENCE 
		rename groupvar Ei
		replace Ei=. if Ei==0
	**BJS FE 
		egen statemonth=group(statefips month)
		local bjs_controls1="month age covid  male period1_start statefips year"	
	*******************************
	**BORUSYAK FOR OUTCOMES THAT APPEAR EVERY YEAR 
	*******************************
	foreach y in "exercise_lm"  "cardioweek_lm" {	 						 
		**All, Full FE 
		eststo clear
		di "outcome `y', sample=All, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt], fe(`bjs_controls1' statemonth) cluster(statefips) 
		sum `y' if e(sample)==1
		
		**Male , Full FE 
		eststo clear
		di "outcome `y', sample=Male, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==1, fe(`bjs_controls1' statemonth) cluster(statefips) 
		sum `y' if e(sample)==1
		
		**Female , Full FE 
		eststo clear
		di "outcome `y', sample=Female, FE1"
		eststo reg1: did_imputation  `y' statefips yearmonth Ei [aw=_llcpwt] if male==0, fe(`bjs_controls1' statemonth) cluster(statefips) 
		sum `y' if e(sample)==1
		}	
	
*******************************************************
**Table A13: Adjacent county 
*******************************************************
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
	**Keep non-RML states
		keep if (statefips==1|statefips==5|statefips==12|statefips==13|statefips==15|statefips==16|statefips==18|statefips==19|statefips==20|statefips==21|statefips==22|statefips==28|statefips==31|statefips==33|statefips==37|statefips==38|statefips==39|statefips==40|statefips==42|statefips==45|statefips==46|statefips==47|statefips==48|statefips==49|statefips==54|statefips==55|statefips==56)
	**Groupvar is yea-month: yearmonth=group(year month)
	**Create a groupvar that is associated with the nearest RML implementation in the adjacent state
		drop groupvar 
		gen groupvar=0	
		gen hasneighbor=0
	**For each of these states, What are their neighbor states and what is the earliest RML implemetation date?
	*1. Alabama neighbors (AL): MS (none), FL (none), GA (none), TN (none)
	*2. Arkansas neighbors (AR): TX (none), MO	(2/3/23), OK (none), LA	(none), MS (none), TN (none)
	*3. Florida neighbors (FL): GA (none), AL (none)
	*4. Georgia neighbors (GA): SC (none), AL (none), TN (none), NC	(none), FL (none)
	*5. Hawaii neighbors (HI): No neighbors 
	*6. Iowa neighbors (IA): MN	(start in 2023), SD	(none), IL	(1/1/2020), MO	(2/3/23), NE	(none), WI (none), Jan 2020
		replace groupvar=109 if statefips==19
		replace hasneighbor=1 if statefips==19
	*7. Idahoe neighbors (ID): WY	(none), UT	(none), WA	(7/8/14), OR	(10/1/15), NV	(7/1/2017), MT (1/1/2022)
		replace groupvar=43 if statefips==16
		replace hasneighbor=1 if statefips==16
	*8. Indiana neighbors (IN): KY	(none), MI	(12/1/2019), OH	(none), IL(1/1/2020)
		replace groupvar=108 if statefips==18
		replace hasneighbor=1 if statefips==18
	*9. Kansas neighbors (KS): MO	(2/3/23), CO	(1/1/2014), NE	(none), OK (none)
		replace groupvar=37 if statefips==20
		replace hasneighbor=1 if statefips==20
	**10.Kentucky neighbors (KY): IL	(1/1/20), VA	(none), OH	(none), TN (none), MO	(2/3/23), IN	(none), WV (none)
		replace groupvar=109 if statefips==21
		replace hasneighbor=1 if statefips==21
	*11. Louisiana neighbors (LA), AR (none), TX	(none), MS (none)
	*12 Mississippi neighbors (MS): LA	(none), AL	(none), TN	(none), AR (none)
	*13.North Carolina neighbors (NC): SC	(none), VA	(none), TN	(none), GA (none)
	*14.North Dakota neighbors (ND): ND	(none), MN	(none), MT	(1/1/2022), SD (none)
	*15.Nebraska neighbors (NE): CO	(1/1/2014), SD	(none), MO	(2/3/23), WY	(none), IA	(none), KS (none)
		replace groupvar=37 if statefips==31
		replace hasneighbor=1 if statefips==31
	*16.New Hampshire neighbors (NH), MA	(11/20/2018), VT	(10/1/2022), ME (10/9/2020)
		replace groupvar=85 if statefips==33
		replace hasneighbor=1 if statefips==33
	*17.Ohio neighbors (OH): KY	(none), PA	(none), WV	(none), MI	(12/1/2019), IN (none )
		replace groupvar=108 if statefips==39
		replace hasneighbor=1 if statefips==39
	*18.Oklahoma neighbors (OK): TX	(none), MO	(2/3/23), NM	(4/1/2022), CO	(1/1/2014) , KS	(none), AR (none)
		replace groupvar=37 if statefips==40
		replace hasneighbor=1 if statefips==40
	*19.Pennsylvania neighbors (PA): MD	(7/1/2023), OH	(none), NY	(12/29/22), NJ (4/20/2022), WV	(none), DE (2024)
	*20. South Carolina neighbors (SC): GA	(none), NC (none)
	*21.South Dakota neighbors (SD): MN	(none), NE	(none), WY	(none), MT	(1/1/2022), IA	(none), ND (none)
	*22.Tennessee neighbors (TN): AR	(none), VA	(none), AL	(none), MO	(2/3/23), KY	(none), MS	(none), NC	(none), GA (none)
	*23.Texas neighbors (TX): AR	(none), OK	(none), LA	(none), NM	(4/1/2022)
	*24.Utah neighbors (UT): NV	(7/1/2017), WY	(none), NM	(4/1/2022), AZ	(1/22/2021), ID	(none), CO (1/1/2014) 
		replace groupvar=37 if statefips==49
		replace hasneighbor=1 if statefips==49
	*25.Wisconsin neighbors: MI	(12/1/2019) , IL	(1/1/2020), MN	(none), IA (none)
		replace groupvar=108 if statefips==55
		replace hasneighbor=1 if statefips==55
	*26.West Virginia (WV): MD	(7/1/2023), KY	(none), PA	(none), VA	(none), OH (none)
	*27.Wyoming neighbors: UT	(none), SD	(none), NE	(none), ID	(none), CO	(1/1/2014), MT (1/1/2022)
		replace groupvar=37 if statefips==56
		replace hasneighbor=1 if statefips==56
	** Borsuyak grouping (monthly)
		*drop Ei
		gen Ei=.
		replace Ei=groupvar if hasneighbor==1
		replace Ei=. if Ei==0
	*******************************************
	**Adjacent states
	*****************************************
	**Groups 
		gen statemonth=group(statefips month)
		keep if age>=21 & age!=. 
	**BJS FE 
		local bjs_controls1="month age covid  male period1_start statefips year"	
		local bjs_controls2="month age covid  male period1_start statefips year statemonth"

	*Exercise_lm			 
		**All
		eststo reg1: did_imputation  exercise_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=., fe(`bjs_controls1') cluster(statefips) 
		sum exercise_lm [aw=_llcpwt] if e(sample)==1
		
		**Male
		eststo reg1: did_imputation  exercise_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=. & male==1, fe(`bjs_controls1') cluster(statefips) 
		sum exercise_lm [aw=_llcpwt] if e(sample)==1
		
		**Female
		eststo reg1: did_imputation  exercise_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=. & male==0, fe(`bjs_controls1') cluster(statefips) 
		sum exercise_lm [aw=_llcpwt] if e(sample)==1
		
	**cardioweek_lm			 
		**All
		eststo reg1: did_imputation  cardioweek_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=., fe(`bjs_controls2') cluster(statefips) 
		sum cardioweek_lm [aw=_llcpwt] if e(sample)==1
		
		**Male
		eststo reg1: did_imputation  cardioweek_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=. & male==1, fe(`bjs_controls2') cluster(statefips) 
		sum `y' [aw=_llcpwt] if e(sample)==1
		
		**Female
		eststo reg1: did_imputation  cardioweek_lm statefips yearmonth Ei [aw=_llcpwt] if age>=21 & age!=. & male==0, fe(`bjs_controls2') cluster(statefips) 
		sum cardioweek_lm [aw=_llcpwt] if e(sample)==1


************************************************************************
**Figure 2: BRFSS event study 
************************************************************************
	clear
	use  "`brfss_data'"
	**Keep relevant years
		keep if year>=2011 & year<=2021
	**Universe 1: All 21plus (dummy for gender and age)
		keep if age>=21 & age!=.
		local bjs_controls1="month age covid  male period1_start statefips year"
	**Graph 
		did_imputation exercise_lm statefips year rml_start [aw=_llcpwt], fe(`bjs_controls1')  horizons(0/4) pretrend(4) cluster(statefips) 
		*event_plot
		did_imputation cardioweek_lm statefips year rml_start [aw=_llcpwt], fe(`bjs_controls1')  horizons(0/4) pretrend(4) cluster(statefips) 
		event_plot

